package br.com.vestibulation.dao;
import java.sql.*;
import java.util.Properties;

public class ConnectionFactory{
    protected Connection conn;
    protected PreparedStatement stmt;
    protected ResultSet rs;
    protected String info;

    protected boolean abrir() throws Exception{
        try{
            Properties connectionProps = new Properties();
            connectionProps.put("user", "admin");
            connectionProps.put("password", "admin");
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
            conn = DriverManager.getConnection("jdbc:derby://localhost:1527/Vestibulation", connectionProps);
            return true;
        }
        catch(Exception ex){
            info = "Erro ao abrir conexão com o banco de dados!";
            throw ex;
        }
    }

    protected void fechar(){
        try{
            conn.close();
        }
        catch(Exception ex){
            info = "Erro ao fechar conexão com o banco de dados!";
        }
    }
    
    public String getInfo(){
        return info;
    }

}
